package util;

public class Line2D {
	
	public Point2f a,b;
	private Color3f color;
	
	public Line2D(Point2f a, Point2f b, Color3f c){
		this.a = a;
		this.b = b;
		this.color = c;
	}
	
	public Line2D(Vector3f v1, Vector3f v2){
		this(v1, v2, new Color3f(1,0,0));
	}
	
	public Line2D(Vector3f v1, Vector3f v2, Color3f c){
		this.a = new Point2f(v1.x,v1.y);
		this.b = new Point2f(v2.x,v2.y);
		this.color = c;
	}
	
	public void swapAandB(){
		Point2f temp = a;
		a = b;
		b = temp;
	}

	public Line2D(int x0, int y0, int x1, int y1, Color3f c){
		Point2f a = new Point2f(x0,y0);
		Point2f b = new Point2f(x1,y1);
		this.a = a;
		this.b = b;
		this.color = c;
	}
	
	public Line2D(float x, float y, float x2, float y2) {
		this(new Point2f(x,y), new Point2f(x2,y2), new Color3f(1,0,0));
	}

	public Color3f getColor(){
		return color;
	}
	
	public float getSlope(){
		return (b.y - a.y) / (b.x - a.x);
	}
	
	/**
	 * Returns the value of the implicit equation of this line.
	 * If (x,y) is on the line, this returns 0.
	 * If (x,y) is above the line, this returns a negative value.
	 * If (x,y) is 
	 * @param x
	 * @param y
	 * @return
	 */
	public float implicit(float x, float y){
		return (a.y - b.y) * x + (b.x - a.x) * y + a.x * b.y - b.x * a.y;
	}

}
